import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import axios from 'axios'
import ElementUI from 'element-ui'

import 'element-ui/lib/theme-chalk/index.css'
import '@/styles/style.scss'
import '@/styles/icons/iconfont.js'
import '@/utils/utils.js'

Vue.use(ElementUI,{size: 'small'});
Vue.prototype.$axios = axios;

Vue.config.productionTip = false
// echarts图
import * as echarts from 'echarts'
Vue.prototype.$echarts = echarts

new Vue({
  router,
  store,
  created(){
    //路由拦截
    this.$store.commit('menu/setToken', localStorage.getItem('token'));
    router.beforeEach((to, from, next) => {
        if(to.path == '/'){
            next();
        }else{
            const token = this.$store.state.menu.token;
            if(token == null || token === ''){
                next('/')
            }else{
                next();
            }
        }
    })
  },
  render: h => h(App)
}).$mount('#app')
